package com.lovo.cloud.interceptor;

import com.lovo.cloud.service.PermissionService;
import com.lovo.model.dto.UserDTO;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author luo
 * @description
 * @date 2020/12/2 11:13
 */
@Component
public class PermissionInterceptor implements HandlerInterceptor {


    @Resource
    private PermissionService permissionService;

    //预处理
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        UserDTO userDTO = new UserDTO();
        userDTO.setUserName(username);
        userDTO.setUserPwd(password);
        return permissionService.isLogin(userDTO);
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
